#include<stdio.h>
#include<stdlib.h>
#define SIZE 3
#define LOCALFILE "X:\\c\\test3.txt"
struct Student
{
    char name[10];
    int num;
    int age;
    char addr[15];
}stu[SIZE];

void save()
{
    FILE *fp;
    int i;
    if((fp=fopen(LOCALFILE,"w"))==NULL)
    {
        printf("can not open file.\n");
        exit(0);
    }
    for(i=0;i<SIZE;i++)
    {
        if(fwrite(&stu[i],sizeof(struct Student),1,fp)==0)//地址，单个字节大小，字节数，文件指针，读取成功返回0
            printf("c\n");
        
    }
    fclose(fp);

}
int main()
{
    int i;
    printf("Please enter data of students:\n");
    for(i=0;i<SIZE;i++)
    {
        scanf("%s%d%d%s",stu[i].name,&stu[i].num,&stu[i].age,stu[i].addr);
    }
    save();
    return 0;
}
